package com.itheima.Test01;

public class Demo03 {
    public static void main(String[] args) {
        String s1 = "good good study, day day up";
        System.out.println("s1 = " + s1);

        //需求1:将当前字符串中的字母转大写
        String s2 = s1.toUpperCase();
        System.out.println("s2 =" + s2);

        //需求2:将当前字符串中的字母转小写
        String s3 = s2.toLowerCase();
        System.out.println("s3 =" + s3);

        //需求3:将s5首位的空格消除
        String s5 = "     good good study, day day up";
        String trim = s1.trim();
        System.out.println("trim = " + trim);


        String s4 = "锄禾日当午,汗滴禾下土";
        //需求4:判断s4中是否包含"日" ---判断班级中名字里带"辉"字的人名有多少!
        boolean flag = s4.contains("日");
        System.out.println("flag =" + flag);

        //判断name是不是姓"德玛"
        //startsWith: 从前往后逐位比较
        String name = "德玛西亚";
        boolean flagl = name.startsWith("德玛");
        System.out.println("flagl = " + flagl);

        //需求6:判断name是不是以"西亚"结尾
        //endsWith: 从后往前逐位比较
        boolean flag2 = name.endsWith("西亚");
        System.out.println("flag2 =" + flag2);

        String msg = "黑化肥黑发挥会发黑";
        //需求7: 获取"黑"在msg中第一次出现的索引
        int firstIndex = msg.indexOf("黑");
        System.out.println("firstIndex =" + firstIndex);

        //需求7.5: 获取"黑"在msg 中第二次出现的索引
        String substring = msg.substring(firstIndex + 1);
        System.out.println("substring =" + substring);
        int midIndex = substring.indexOf("黑");
        System.out.println("midIndex =" + (midIndex + firstIndex +1));

        //需求8:获取"黑"在msg中的最后一次出现的索引
        int lastIndex = msg.lastIndexOf("黑");
        System.out.println("lastIndex =" + lastIndex);

    }
}
